package socketdemo.bio;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author zoush
 * @createTime 2024/12/04  15:18
 */
public class UserInputHandler implements Runnable {
    private ChatClientDemo client;

    public UserInputHandler(ChatClientDemo client) {
        this.client = client;
    }

    @Override
    public void run() {
        //接收用户输入的消息
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            try {
                //不停的获取reader中的System.in，实现了等待用户输入的效果
                String input = reader.readLine();
                client.sendToServer(input);
                if (input.equals("quit"))
                    break;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
